package org.wangzs.blog.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.wangzs.blog.dao.inner.IPostDAO;
import org.wangzs.blog.entity.Page;
import org.wangzs.blog.entity.TPost;
import org.wangzs.blog.service.inner.IPostService;
import org.wangzs.blog.util.Const;


@Service("PostServiceImpl")
public class PostServiceImpl implements IPostService {
	
	@Resource(name = "PostDAOImpl")
	private IPostDAO postDAO;
	
	@Override
	public TPost get(String postId) {
		TPost post = postDAO.get(postId);
		return post;
	}
	
	@Override
	public Page<TPost> get(int pageSize, int pageNum) {
		return postDAO.get(pageSize, pageNum);
	}
	
	@Override
	public int save(TPost post) throws DataAccessException {
		post.setCreatedTime(new Date());
		post.setDeletedFlag(Const.FLAG_NO);
		return postDAO.save(post);
	}

	@Override
	public int update(TPost post) {
		return postDAO.update(post);
	}

	@Override
	public int delete(String postId) {
		return postDAO.delete(postId);
	}

	@Override
	public int getTotalNum() {
		return postDAO.getTotalNum();
	}

}
